package com.kingviker.example.handler3;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.nio.charset.Charset;

public class MyServerHandler extends SimpleChannelInboundHandler<MyCustomProtocol> {

    private  int count;



    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyCustomProtocol msg) throws Exception {
        count++;
        System.out.println("length:"+msg.getLength());
        System.out.println("content:"+new String(msg.getContent(),Charset.forName("utf-8")));
//        ByteBuf responseByteBuf = Unpooled.copiedBuffer(UUID.randomUUID().toString(), Charset.forName("utf-8"));
//        ctx.writeAndFlush(responseByteBuf);

    }

}
